home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / GCSTRUCT.H < prev    next >
Text File  |  1994-07-23  |  6KB  |  302 lines

  1.  
  2. /*
  3.  
  4.      Internal header file for GCOOPE version 1.0
  5.  
  6.            by Brian Lee Price
  7.  
  8.        Released as Public Domain  July, 1994.
  9.  
  10. */
  11.  
  12.  
  13. /* typedef object as long give error if long smaller than void * */
  14.  
  15. #if sizeof(long)>=sizeof(void *)
  16.   typedef long object;
  17. #else
  18.   #error UNSUPPORTED MEMORY MODEL
  19. #endif
  20.  
  21.  
  22. /*
  23.      typedef tag as int unless 2*sizeof(int) > sizeof long
  24.      otherwise typedef tag as short unless 2 shorts are larger than
  25.      a long then give error
  26. */
  27.  
  28. #if sizeof(long)>=(2*sizeof(int))
  29.   typedef int tag;
  30. #elif sizeof(long)>=(2*sizeof(short))
  31.   typedef short tag;
  32. #else
  33.   #error UNSUPPORTED OBJECT SIZE
  34. #endif
  35.  
  36. #if sizeof(tag)==1
  37.   #define SIGNMASK 0x7F
  38. #elif sizeof(tag)==2
  39.   #define SIGNMASK 0x7FFF
  40. #elif sizeof(tag)==4
  41.   #define SIGNMASK 0x7FFFFFFFL
  42. #else
  43.   #error UNSUPPORTED TAG SIZE
  44. #endif
  45.  
  46. #ifndef NULL
  47.   #define NULL ((void *) 0L)
  48. #endif
  49.  
  50. #define MAX_CHAR 0x7F
  51. #define MAX_USHORT 0xFFFF
  52. #define MAX_GEN 0x7FFF
  53.  
  54. /*   common type definitions   */
  55.  
  56. typedef unsigned char byte;
  57. typedef unsigned short int word;
  58. typedef unsigned long int dword;
  59.  
  60. typedef tag generic;
  61. typedef object (*method)(object,...);
  62. typedef method (*dispatch)(generic,...);
  63.  
  64.  
  65. /* objTag definition for object handle structure */
  66.  
  67. typedef struct {
  68.     tag    tag;
  69.     tag    fext;
  70.     } objHndl;
  71.  
  72.  
  73. /* process status definitions */
  74.  
  75. typedef enum {FUNCOKAY, FUNCFAIL} stat;
  76.  
  77. /* boolean definition */
  78.  
  79. typedef enum {FALSE, TRUE} boolean;
  80.  
  81.  
  82. /* global variable declarations */
  83.  
  84. #ifndef __GARBAGE__
  85.   extern byte curProcID;
  86. #else
  87.   byte curProcID;
  88. #endif
  89.  
  90. #ifndef FIRST_GCOOPE_ERROR
  91.   #define FIRST_GCOOPE_ERROR 1
  92. #endif
  93.  
  94. typedef enum { ERR_OUT_OF_MEM=FIRST_GCOOPE_ERROR, ERR_BAD_HANDLE,
  95.         ERR_BAD_CLASS, LAST_GCOOPE_ERROR } gcErrTypes;
  96.  
  97.  
  98. #ifdef __OBJECT_DEFINITION__
  99.  
  100.   char *    gcerrmsg[]={    "Out of memory",
  101.                 "Bad object handle",
  102.                 "Bad class reference",
  103.                 "Undefined error type" };
  104.   object     Object;
  105.  
  106.   generic          New;
  107.   generic    Kill;
  108.   generic    Err;
  109.   generic    GFclassOf;                /* these symbols prefaced with */
  110.   generic    GFivSize;           /* GF for compatibility with   */
  111.   generic    GFrespondsTo;             /* the experimental strong     */
  112.   generic    GFdeepCopy;               /* typing option.         */
  113.   generic    GFshallowCopy;
  114.  
  115. #else
  116.  
  117.   extern char *     gcerrmsg[];
  118.   extern object         Object;
  119.   extern generic    New;
  120.   extern generic    Kill;
  121.   extern generic    Err;
  122.   extern generic    GFclassOf;
  123.   extern generic    GFivSize;
  124.   extern generic    GFrespondsTo;
  125.   extern generic    GFdeepCopy;
  126.   extern generic    GFshallowCopy;
  127.  
  128. #endif
  129.  
  130. #ifdef __CLASS_DEFINITION__
  131.   object Class;
  132. #else
  133.   extern object Class;
  134. #endif
  135.  
  136. #define END ((object) 0L)
  137. #define MIN_METHOD_ADD (8)
  138.  
  139. /* prototypes of public kernel functions */
  140.  
  141. stat        addGMthd(object, generic, method);
  142. generic     addGeneric( method defMthd);
  143. stat        cpyGMas(object, generic, object, generic);
  144. void *         getCVptr(object);
  145. void *         getIVptr(object);
  146. stat        inhMthd(object, object);
  147. int        tagCmg(const void *, const void *);
  148. void *        makeInst(object *);
  149. stat        makePerm(object);
  150. method        g(generic,...);
  151. stat        rmvGMthd(object, generic);
  152. int        rmvGeneric(generic GenFunc);
  153. object      steer(object, object);
  154. void *        s_calloc(unsigned, unsigned);
  155. void         s_free(void *);
  156. void *        s_malloc(unsigned);
  157. void *         s_realloc(void *, unsigned);
  158. object        bounceBack(object,...);
  159.  
  160. /* prototype for the pseudo-class Object installation routine */
  161. stat        Object_Install(void);
  162.  
  163. stat        Class_Install(void);
  164.  
  165. #ifndef _EXTERNAL_
  166.  
  167.   #define DYNLIST_STRU word elemSize,firstFree,maxElems;void * listPtr
  168.  
  169.   #define MAX_BLOCK_SIZE (65523L)
  170.  
  171.   typedef struct {
  172.     DYNLIST_STRU;
  173.     } dynList;
  174.  
  175.   #define MIN_LIST_ADD 16
  176.  
  177.  
  178.   /* the following functions are defined in listmgr.c */
  179.  
  180.   int         addItem(void *listAdr, int elemSize);
  181.   int         rmvItem(void *listAdr, int elemNdx);
  182.   stat         compactList(void *listAdr, boolean sorted);
  183.  
  184.  
  185.   #ifdef __OBJECTS__
  186.   dynList objList={0,0,0,(void *) 0L};
  187.   #else
  188.   extern dynList objList;
  189.   #endif
  190.  
  191.  
  192.   typedef struct {
  193.     void *        objDef;
  194.     byte        procID,
  195.             lastAcc;
  196.     } objectEntry;
  197.  
  198.   #define PERM_PROC_ID 255
  199.   #define INIT_AGE 255
  200.   #define BAD_OBJ 0x7FFF
  201.  
  202.   /* the following functions are defined in objlist.c */
  203.  
  204.   objectEntry *     getObject(tag objTag);
  205.   void *         getObjDef(tag objTag);
  206.   int            addObject(void * objDef, byte procID);
  207.   int            rmvObject(tag objTag);
  208.  
  209.  
  210.   #ifdef __GENERICS__
  211.   dynList genTable;
  212.   #else
  213.   extern dynList genTable;
  214.   #endif
  215.  
  216.  
  217.   typedef struct {
  218.     tag            class;
  219.     tag            owner;
  220.     method            instMethod;
  221.     } genMethod;
  222.  
  223.  
  224.   typedef struct {
  225.     DYNLIST_STRU;
  226.     method            defMthd;
  227.     } genEntry;
  228.  
  229.  
  230.   /* the following functions are defined in genlist.c */
  231.  
  232.   int        tagCmg(const void *, const void *);
  233.   genMethod *    getMthd(generic genFunc, tag clsTag);
  234.   stat        addMethod(generic genFunc, method addMthd,
  235.               tag clsTag, tag owner);
  236.   stat        rmvMethod(generic genFunc, tag clsTag);
  237.  
  238.   /* the following functions are defined in garbage.c */
  239.  
  240.   void *         s_calloc(unsigned nitems, unsigned size);
  241.   void           s_free(void * block);
  242.   void *         s_malloc(unsigned size);
  243.   void *         s_realloc(void * block, unsigned newSize);
  244.   void            outOfElems(void);
  245.  
  246.   stat            makePerm(object instance);
  247.  
  248.  
  249.   #define MINDCRVAL 1
  250.   #define MAXDCRVAL 25
  251.   #define MAXSHIFTVAL 9
  252.   #define MINSHIFTVAL 4
  253.   #define TIMVAL 1000
  254.   #define MAX_ERR_TRY 256
  255.  
  256.  
  257.   typedef struct {
  258.     tag        class;
  259.     int        cvSize,
  260.         ivSize,
  261.         totSize,
  262.         numSuper,
  263.         numMthds;
  264.     void *    loadAdr;
  265.     char    cVars[1];
  266.     } classEntry;
  267.  
  268.   typedef struct {
  269.     tag        class,
  270.         offset;
  271.     } superEntry;
  272.  
  273.  
  274.  
  275.   /* the following functions are defined in funcdisp.c */
  276.  
  277.   method         g(generic,...);
  278.   object         steer(object class, object instance);
  279.   void *        getIVptr(object instance);
  280.   void *        getCVptr(object class);
  281.   void *        makeInst(object * instPtr);
  282.  
  283.  
  284.  
  285.   typedef struct {
  286.     generic        genTag;
  287.     method        clsMthd;
  288.     } methodEntry;
  289.  
  290.  
  291.   /* prototype for the pseudo-class Class routines */
  292.  
  293.   stat        Class_Install(void);
  294.   stat        inhMthd(object class, object super);
  295.   stat        addGMthd(object class, generic genFunc, method addMethod);
  296.   stat        rmvGMthd(object class, generic genFunc);
  297.   stat        cpyGMas(object newClass, generic newGenFunc,
  298.                 object oldClass, generic oldGenFunc);
  299.  
  300. #endif
  301.  
  302.